package com.example.labb1;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
 
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater=null;
	
	public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d ){
		
		activity = a;
		data = d;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
	}
	
	
	
	@Override
	public int getCount() {
		
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		
		return position;
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if(convertView==null)
			vi = inflater.inflate(R.layout.list_row, null);
		
		TextView title = (TextView)vi.findViewById(R.id.title);
		TextView artist = (TextView)vi.findViewById(R.id.artist);
		TextView duration = (TextView)vi.findViewById(R.id.duration);
		
		HashMap<String, String> song = new HashMap<String, String>();
		song = data.get(position);
		
		title.setText(song.get(FragmentOne.KEY_TITLE));
		artist.setText(song.get(FragmentOne.KEY_ARTIST));
        duration.setText(song.get(FragmentOne.KEY_DURATION));
		
		
		return vi;
	}

}
